home *** CD-ROM | disk | FTP | other *** search
/ Aminet 48 / Aminet 48 (2002)(GTI - Schatztruhe)[!][Apr 2002].iso / Aminet / text / edit / vim60rt.lha / Vim / vim60 / doc / visual.txt < prev    next >
Encoding:
Text File  |  2001-09-26  |  18.8 KB  |  482 lines

  1. *visual.txt*    For Vim version 6.0.  Last change: 2001 Sep 16
  2.  
  3.  
  4.           VIM REFERENCE MANUAL    by Bram Moolenaar
  5.  
  6.  
  7. Visual mode                *Visual* *Visual-mode* *visual-mode*
  8.  
  9. Visual mode is a flexible and easy way to select a piece of text for an
  10. operator.  It is the only way to select a block of text.
  11.  
  12. This is introduced in section |04.4| of the user manual.
  13.  
  14. 1. Using Visual mode            |visual-use|
  15. 2. Starting and stopping Visual mode    |visual-start|
  16. 3. Changing the Visual area        |visual-change|
  17. 4. Operating on the Visual area        |visual-operators|
  18. 5. Blockwise operators            |blockwise-operators|
  19. 6. Repeating                |visual-repeat|
  20. 7. Examples                |visual-examples|
  21. 8. Select mode                |Select-mode|
  22.  
  23. {Vi has no Visual mode, the name "visual" is used for Normal mode, to
  24. distinguish it from Ex mode}
  25. {not available when the |+visual| feature was disabled when compiling}
  26.  
  27. ==============================================================================
  28. 1. Using Visual mode                    *visual-use*
  29.  
  30. Using Visual mode consists of three parts:
  31. 1. Mark the start of the text with "v", "V" or CTRL-V.
  32.    The character under the cursor will be used as the start.
  33. 2. Move to the end of the text.
  34.    The text from the start of the Visual mode up to and including the
  35.    character under the cursor is highlighted.
  36. 3. Type an operator command.
  37.    The highlighted characters will be operated upon.
  38.  
  39. The 'highlight' option can be used to set the display mode to use for
  40. highlighting in Visual mode.
  41. The 'virtualedit' option can be used to allow positioning the cursor to
  42. positions where there is no actual character.
  43.  
  44. The highlighted text includes the character under the cursor.  On terminals
  45. where it is possible to make the cursor invisible the cursor position is
  46. also highlighted.  On terminals where this is not possible the cursor is
  47. displayed normally.  If your cursor cannot be made invisible and you want Vim
  48. to highlight the character under the cursor anyway, you could set the 't_cv'
  49. and 't_ci' options to something harmless, for example: >
  50.     :set t_cv=^[^[ t_ci=^[^[
  51.  
  52. With "v" the text before the start position and after the end position will
  53. not be highlighted.  However, All uppercase and non-alpha operators, except
  54. "~", will work on whole lines anyway.  See the list of operators below.
  55.  
  56.                             *visual-block*
  57. With CTRL-V (blockwise Visual mode) the highlighted text will be a rectangle
  58. between start position and the cursor.  However, some operators work on whole
  59. lines anyway (see the list below).  The change and substitute operators will
  60. delete the highlighted text and then start insertion at the top left
  61. position.
  62.  
  63. ==============================================================================
  64. 2. Starting and stopping Visual mode            *visual-start*
  65.  
  66.                         *v* *characterwise-visual*
  67. v            start Visual mode per character.
  68.  
  69.                         *V* *linewise-visual*
  70. V            start Visual mode linewise.
  71.  
  72.                         *CTRL-V* *blockwise-visual*
  73. CTRL-V            start Visual mode blockwise.  Note: Under Windows
  74.             CTRL-V could be mapped to paste text, it doesn't work
  75.             to start Visual mode then, see |CTRL-V-alternative|.
  76.  
  77. If you use <Esc>, click the left mouse button or use any command that
  78. does a jump to another buffer while in Visual mode, the highlighting stops
  79. and no text is affected.  Also when you hit "v" in characterwise Visual mode,
  80. "CTRL-V" in blockwise Visual mode or "V" in linewise Visual mode.  If you hit
  81. CTRL-Z the highlighting stops and the editor is suspended or a new shell is
  82. started |CTRL-Z|.
  83.  
  84.           new mode after typing:        *v_v* *v_CTRL-V* *v_V*
  85. old mode         "v"          "CTRL-V"             "V"    ~
  86.  
  87. Normal            Visual       blockwise Visual      linewise Visual
  88. Visual            Normal       blockwise Visual      linewise Visual
  89. blockwise Visual    Visual       Normal          linewise Visual
  90. linewise Visual     Visual       blockwise Visual      Normal
  91.  
  92.                             *gv* *v_gv*
  93. gv            Start Visual mode with the same area as the previous
  94.             area and the same mode.  In Visual mode the current and
  95.             the previous Visual area are exchanged.
  96.  
  97.                             *<LeftMouse>*
  98. <LeftMouse>        Set the current cursor position.  If Visual mode is
  99.             active it is stopped.  Only when 'mouse' option is
  100.             contains 'n' or 'a'.  If the position is within 'so'
  101.             lines from the last line on the screen the text is
  102.             scrolled up.  If the position is within 'so' lines from
  103.             the first line on the screen the text is scrolled
  104.             down.
  105.  
  106.                             *<RightMouse>*
  107. <RightMouse>        Start Visual mode if it is not active.  The text from
  108.             the cursor position to the position of the click is
  109.             highlighted.  If Visual mode was already active move
  110.             the start or end of the highlighted text, which ever
  111.             is closest, to the position of the click.  Only when
  112.             'mouse' option contains 'n' or 'a'.
  113.  
  114.             Note: when 'mousemodel' is set to "popup",
  115.             <S-LeftMouse> has to be used instead of <RightMouse>.
  116.  
  117.                             *<LeftRelease>*
  118. <LeftRelease>        This works like a <LeftMouse>, if it is not a
  119.             the same position as <LeftMouse>.  In an xterm you
  120.             won't see the selected area until the button is
  121.             released, unless there is access to the display where
  122.             the xterm is running (via the DISPLAY environment
  123.             variable or the -display argument).  Only when 'mouse'
  124.             option contains 'n' or 'a'.
  125.  
  126. If Visual mode is not active and the "v", "V" or CTRL-V is preceded with a
  127. count, the size of the previously highlighted area is used for a start.  You
  128. can then move the end of the highlighted area and give an operator.  The type
  129. of the old area is used (character, line or blockwise).
  130. - Linewise Visual mode: The number of lines is multiplied with the count.
  131. - Blockwise Visual mode: The number of lines and columns is multiplied with
  132.   the count.
  133. - Normal Visual mode within one line: The number of characters is multiplied
  134.   with the count.
  135. - Normal Visual mode with several lines: The number of lines is multiplied
  136.   with the count, in the last line the same number of characters is used as
  137.   in the last line in the previously highlighted area.
  138. The start of the text is the Cursor position.  If the "$" command was used as
  139. one of the last commands to extend the highlighted text, the area will be
  140. extended to the rightmost column of the longest line.
  141.  
  142. If you want to highlight exactly the same area as the last time, you can use
  143. "gv" |gv| |v_gv|.
  144.  
  145.                             *v_CTRL-C*
  146. CTRL-C            In Visual mode: Stop Visual mode.  When insert mode is
  147.             pending (the mode message shows
  148.             "-- (insert) VISUAL --"), it is also stopped.
  149.  
  150. ==============================================================================
  151. 3. Changing the Visual area                *visual-change*
  152.  
  153.                             *v_o*
  154. o            Go to Other end of highlighted text: The current
  155.             cursor position becomes the start of the highlighted
  156.             text and the cursor is moved to the other end of the
  157.             highlighted text.  The highlighted area remains the
  158.             same.
  159.  
  160.                             *v_O*
  161. O            Go to Other end of highlighted text.  This is like
  162.             "o", but in Visual block mode the cursor moves to the
  163.             other corner in the same line.  When the corner is at
  164.             a character that occupies more than one position on
  165.             the screen (e.g., a <Tab>), the highlighted text may
  166.             change.
  167.  
  168.                             *v_$*
  169. When the "$" command is used with blockwise Visual mode, the right end of the
  170. highlighted text will be determined by the longest highlighted line.  This
  171. stops when a motion command is used that does not move straight up or down.
  172.  
  173. For moving the end of the block many commands can be used, but you cannot
  174. use Ex commands, commands that make changes or abandon the file.  Commands
  175. (starting with) ".pPiIaAO&", CTRL-^, "Z", CTRL-], CTRL-T, CTRL-R, CTRL-I
  176. and CTRL-O cause a beep and Visual mode continues.
  177.  
  178. When switching to another window on the same buffer, the cursor position in
  179. that window is adjusted, so that the same Visual area is still selected.  This
  180. is especially useful to view the start of the Visual area in one window, and
  181. the end in another.  You can then use <RightMouse> (or <S-LeftMouse> when
  182. 'mousemodel' is "popup") to move either end of the Visual area.
  183.  
  184. ==============================================================================
  185. 4. Operating on the Visual area                *visual-operators*
  186.  
  187. The operators that can be used are:
  188.     ~    switch case                    |v_~|
  189.     d    delete                        |v_d|
  190.     c    change (4)                    |v_c|
  191.     y    yank                        |v_y|
  192.     >    shift right (4)                    |v_>|
  193.     <    shift left (4)                    |v_<|
  194.     !    filter through external command (1)        |v_!|
  195.     =    filter through 'equalprg' option command (1)    |v_=|
  196.     gq    format lines to 'textwidth' length (1)        |v_gq|
  197.  
  198. The objects that can be used are:
  199.     aw    a word (with white space)            |v_aw|
  200.     iw    inner word                    |v_iw|
  201.     aW    a WORD (with white space)            |v_aW|
  202.     iW    inner WORD                    |v_iW|
  203.     as    a sentence (with white space)            |v_as|
  204.     is    inner sentence                    |v_is|
  205.     ap    a paragraph (with white space)            |v_ap|
  206.     ip    inner paragraph                    |v_ip|
  207.     ab    a () block (with braces)            |v_ab|
  208.     ib    inner () block                    |v_ib|
  209.     aB    a {} block (with brackets)            |v_aB|
  210.     iB    inner {} block                    |v_iB|
  211.  
  212. Additionally the following commands can be used:
  213.     :    start ex command for highlighted lines (1)    |v_:|
  214.     r    change (4)                    |v_r|
  215.     s    change                        |v_s|
  216.     C    change (2)(4)                    |v_C|
  217.     S    change (2)                    |v_S|
  218.     R    change (2)                    |v_R|
  219.     x    delete                        |v_x|
  220.     D    delete (3)                    |v_D|
  221.     X    delete (2)                    |v_X|
  222.     Y    yank (2)                    |v_Y|
  223.     p    put                        |v_p|
  224.     J    join (1)                    |v_J|
  225.     U    make uppercase                    |v_U|
  226.     u    make lowercase                    |v_u|
  227.     ^]    find tag                    |v_CTRL-]|
  228.     I    block insert                    |v_b_I|
  229.     A    block append                    |v_b_A|
  230.  
  231. (1): Always whole lines, see |:visual_example|.
  232. (2): Whole lines when not using CTRL-V.
  233. (3): Whole lines when not using CTRL-V, delete until the end of the line when
  234.      using CTRL-V.
  235. (4): When using CTRL-V operates on the block only.
  236.  
  237. Note that the ":vmap" command can be used to specifically map keys in Visual
  238. mode.  For example, if you would like the "/" command not to extend the Visual
  239. area, but instead take the highlighted text and search for that: >
  240.     :vmap / y/<C-R>"<CR>
  241. (In the <> notation |<>|, when typing it you should type it literally; you
  242. need to remove the 'B' and '<' flags from 'cpoptions')
  243.  
  244. If you want to give a register name using the """ command, do this just before
  245. typing the operator character: "v{move-around}"xd".
  246.  
  247. If you want to give a count to the command, do this just before typing the
  248. operator character: "v{move-around}3>" (move lines 3 indents to the right).
  249.  
  250.                             *{move-around}*
  251. The {move-around} is any sequence of movement commands.  Note the difference
  252. with {motion}, which is only ONE movement command.
  253.  
  254. ==============================================================================
  255. 5. Blockwise operators                    *blockwise-operators*
  256.  
  257. {not available when compiled without the |+visualextra| feature}
  258.  
  259. Reminder: Use 'virtualedit' to be able to select blocks that start or end
  260. after the end of a line or halfway a tab.
  261.  
  262. Visual-block Insert                        *v_b_I*
  263. With a blockwise selection, I{string}<ESC> will insert {string} at the start
  264. of block on every line of the block, provided that the line extends into the
  265. block.  Thus lines that are short will remain unmodified.  TABs are split to
  266. retain visual columns.
  267. See |v_b_I_example|.
  268.  
  269. Visual-block Append                        *v_b_A*
  270. With a blockwise selection, A{string}<ESC> will append {string} to the end of
  271. block on every line of the block. There is some differing behavior where the
  272. block RHS is not straight, due to different line lengths:
  273.  
  274. 1. Block was created with <C-v>$
  275.     In this case the string is appended to the end of each line.
  276. 2. Block was created with <C-v>{move-around}
  277.     In this case the string is appended to the end of the block on each line,
  278.     and whitespace is inserted to pad to the end-of-block column.
  279. See |v_b_A_example|.
  280. Note: "I" and "A" behave differently for lines that don't extend into the
  281. selected block.  This was done intentionally, so that you can do it the way
  282. you want.
  283.  
  284. Visual-block change                        *v_b_c*
  285. All selected text in the block will be replaced by the same text string.  When
  286. using "c" the selected text is deleted and Insert mode started.  You can then
  287. enter text (without a line break).  When you hit <Esc>, the same string is
  288. inserted in all previously selected lines.
  289.  
  290. Visual-block Change                        *v_b_C*
  291. Like using "c", but the selection is extended until the end of the line for
  292. all lines.
  293.  
  294.                                 *v_b_<*
  295. Visual-block Shift                        *v_b_>*
  296. The block is shifted by 'shiftwidth'. The RHS of the block is irrelevant. The
  297. LHS of the block determines the point from which to apply a right shift, and
  298. padding includes TABs optimally according to 'ts' and 'et'. The LHS of the
  299. block determines the point upto which to shift left.
  300.     Note: v_< padding is buggy if the Visual Block starts and ends in the same
  301.     TAB. (Vim 5.4c).
  302. See |v_b_>_example|.
  303. See |v_b_<_example|.
  304.  
  305. Visual-block Replace                        *v_b_r*
  306. Every screen char in the highlighted region is replaced with the same char, ie
  307. TABs are split and the virtual whitespace is replaced, maintaining screen
  308. layout.
  309. See |v_b_r_example|.
  310.  
  311.  
  312. ==============================================================================
  313. 6. Repeating                        *visual-repeat*
  314.  
  315. When repeating a Visual mode operator, the operator will be applied to the
  316. same amount of text as the last time:
  317. - Linewise Visual mode: The same number of lines.
  318. - Blockwise Visual mode: The same number of lines and columns.
  319. - Normal Visual mode within one line: The same number of characters.
  320. - Normal Visual mode with several lines: The same number of lines, in the
  321.   last line the same number of characters as in the last line the last time.
  322. The start of the text is the Cursor position.  If the "$" command was used as
  323. one of the last commands to extend the highlighted text, the repeating will
  324. be applied up to the rightmost column of the longest line.
  325.  
  326.  
  327. ==============================================================================
  328. 7. Examples                        *visual-examples*
  329.  
  330.                             *:visual_example*
  331. Currently the ":" command works on whole lines only.  When you select part of
  332. a line, doing something like ":!date" will replace the whole line.  If you
  333. want only part of the line to be replaced you will have to make a mapping for
  334. it.  In a future release ":" may work on partial lines.
  335.  
  336. Here is an example, to replace the selected text with the output of "date": >
  337.     :vmap _a <Esc>`>a<CR><Esc>`<i<CR><Esc>!!date<CR>kJJ
  338.  
  339. (In the <> notation |<>|, when typing it you should type it literally; you
  340. need to remove the 'B' and '<' flags from 'cpoptions')
  341.  
  342. What this does is:
  343. <Esc>        stop Visual mode
  344. `>        go to the end of the Visual area
  345. a<CR><Esc>    break the line after the Visual area
  346. `<        jump to the start of the Visual area
  347. i<CR><Esc>    break the line before the Visual area
  348. !!date<CR>    filter the Visual text through date
  349. kJJ        Join the lines back together
  350.  
  351.                             *visual-search*
  352. Here is an idea for a mapping that makes it possible to do a search for the
  353. selected text: >
  354.     :vmap X y/<C-R>"<CR>
  355.  
  356. (In the <> notation |<>|, when typing it you should type it literally; you
  357. need to remove the 'B' and '<' flags from 'cpoptions')
  358.  
  359. Note that special characters (like '.' and '*') will cause problems.
  360.  
  361. Visual-block Examples                    *blockwise-examples*
  362. With the following text, I will indicate the commands to produce the block and
  363. the results below. In all cases, the cursor begins on the 'a' in the first
  364. line if the test text.
  365. The following modeline settings are assumed :ts=8:sw=4:
  366.  
  367. It will be helpful to
  368. :set hls
  369. /<TAB>
  370. where <TAB> ia a real TAB. This helps visualise the operations.
  371.  
  372. The test text is:
  373.  
  374. abcdefghijklmnopqrstuvwxyz
  375. abc        defghijklmnopqrstuvwxyz
  376. abcdef  ghi        jklmnopqrstuvwxyz
  377. abcdefghijklmnopqrstuvwxyz
  378.  
  379. 1. fo<C-v>3jISTRING<ESC>                    *v_b_I_example*
  380.  
  381. abcdefghijklmnSTRINGopqrstuvwxyz
  382. abc          STRING  defghijklmnopqrstuvwxyz
  383. abcdef  ghi   STRING    jklmnopqrstuvwxyz
  384. abcdefghijklmnSTRINGopqrstuvwxyz
  385.  
  386. 2. fo<C-v>3j$ASTRING<ESC>                    *v_b_A_example*
  387.  
  388. abcdefghijklmnopqrstuvwxyzSTRING
  389. abc        defghijklmnopqrstuvwxyzSTRING
  390. abcdef  ghi        jklmnopqrstuvwxyzSTRING
  391. abcdefghijklmnopqrstuvwxyzSTRING
  392.  
  393. 3. fo<C-v>3j3l<..                        *v_b_<_example*
  394.  
  395. abcdefghijklmnopqrstuvwxyz
  396. abc          defghijklmnopqrstuvwxyz
  397. abcdef  ghi   jklmnopqrstuvwxyz
  398. abcdefghijklmnopqrstuvwxyz
  399.  
  400. 4. fo3j>..                            *v_b_>_example*
  401.  
  402. abcdefghijklmn          opqrstuvwxyz
  403. abc                defghijklmnopqrstuvwxyz
  404. abcdef  ghi                jklmnopqrstuvwxyz
  405. abcdefghijklmn          opqrstuvwxyz
  406.  
  407. 5. fo5l3jrX                            *v_b_r_example*
  408.  
  409. abcdefghijklmnXXXXXXuvwxyz
  410. abc          XXXXXXhijklmnopqrstuvwxyz
  411. abcdef  ghi   XXXXXX    jklmnopqrstuvwxyz
  412. abcdefghijklmnXXXXXXuvwxyz
  413.  
  414. ==============================================================================
  415. 8. Select mode                        *Select* *Select-mode*
  416.  
  417. Select mode looks like Visual mode, but the commands accepted are quite
  418. different.  This resembles the selection mode in Microsoft Windows.
  419. When the 'showmode' option is set, "-- SELECT --" is shown in the last line.
  420.  
  421. Entering Select mode:
  422. - Using the mouse to select an area, and 'selectmode' contains "mouse".
  423.   'mouse' must also contain a flag for the current mode.
  424. - Using a non-printable movement command, with the Shift key pressed, and
  425.   'selectmode' contains "key".  For example: <S-Left> and <S-End>.  'keymodel'
  426.   must also contain "startsel".
  427. - Using "v", "V" or CTRL-V command, and 'selectmode' contains "cmd".
  428. - Using "gh", "gH" or "g_CTRL-H" command in Normal mode.
  429. - From Visual mode, press CTRL-G.            *v_CTRL-G*
  430.  
  431. Commands in Select mode:
  432. - Printable characters, <NL> and <CR> cause the selection to be deleted, and
  433.   Vim enters Insert mode.  The typed character is inserted.
  434. - Non-printable movement commands, with the Shift key pressed, extend the
  435.   selection.  'keymodel' must include "startsel".
  436. - Non-printable movement commands, with the Shift key NOT pressed, stop Select
  437.   mode.  'keymodel' must include "stopsel".
  438. - ESC stops Select mode.
  439. - CTRL-O switches to Visual mode for the duration of one command. *v_CTRL-O*
  440. - CTRL-G switches to Visual mode.
  441.  
  442. Otherwise, typed characters are handled as in Visual mode.
  443.  
  444. When using an operator in Select mode, and the selection is linewise, the
  445. selected lines are operated upon, but like in characterwise selection.  For
  446. example, when a whole line is deleted, it can later be pasted halfway a line.
  447.  
  448.  
  449. Mappings and menus in Select mode.            *Select-mode-mapping*
  450.  
  451. In Select mode the mappings and menus of Visual mode are used.  Before it is
  452. executed, Vim automatically switches to Visual mode, so that the same
  453. behavior as in Visual mode is effective.
  454.  
  455. After the mapping or menu finishes, the selection is enabled again and Select
  456. mode entered, unless the selected area was deleted, another buffer became
  457. the current one or the window layout was changed.
  458.  
  459.                             *gV* *v_gV*
  460. gV            Avoid the automatic reselection of the Visual area
  461.             after a Select mode mapping or menu has finished.
  462.             Put this just before the end of the mapping or menu.
  463.             At least it should be after any operations on the
  464.             selection.
  465.  
  466.                             *gh*
  467. gh            Start Select mode, characterwise.  This is like "v",
  468.             but starts Select mode instead of Visual mode.
  469.             Mnemonic: "get highlighted".
  470.  
  471.                             *gH*
  472. gH            Start Select mode, linewise.  This is like "V",
  473.             but starts Select mode instead of Visual mode.
  474.             Mnemonic: "get Highlighted".
  475.  
  476.                             *g_CTRL-H*
  477. g CTRL-H        Start Select mode, blockwise.  This is like CTRL-V,
  478.             but starts Select mode instead of Visual mode.
  479.             Mnemonic: "get Highlighted".
  480.  
  481.  vim:tw=78:ts=8:ft=help:norl:
  482.